/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rentaldb;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Pop
 */
@Entity
@Table(name = "lease")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Lease.findAll", query = "SELECT l FROM Lease l"),
    @NamedQuery(name = "Lease.findByLeaseid", query = "SELECT l FROM Lease l WHERE l.leaseid = :leaseid"),
    @NamedQuery(name = "Lease.findByStartdate", query = "SELECT l FROM Lease l WHERE l.startdate = :startdate"),
    @NamedQuery(name = "Lease.findByEnddate", query = "SELECT l FROM Lease l WHERE l.enddate = :enddate"),
    @NamedQuery(name = "Lease.findByPropIdAndEndDate", query = "Select l From Lease l Where l.propertyid = :propertyid and l.enddate >= :enddate"),
    @NamedQuery(name = "Lease.findByMonthlypayment", query = "SELECT l FROM Lease l WHERE l.monthlypayment = :monthlypayment"),
    @NamedQuery(name = "Lease.findByDeposit", query = "SELECT l FROM Lease l WHERE l.deposit = :deposit")})
public class Lease implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "leaseid")
    private Integer leaseid;
    @Column(name = "startdate")
    @Temporal(TemporalType.DATE)
    private Date startdate;
    @Column(name = "enddate")
    @Temporal(TemporalType.DATE)
    private Date enddate;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "monthlypayment")
    private Double monthlypayment;
    @Column(name = "deposit")
    private Double deposit;
    @OneToMany(mappedBy = "leaseid")
    private Collection<Payment> paymentCollection;
    @JoinColumn(name = "tenantid", referencedColumnName = "tenant_id")
    @ManyToOne
    private Tenant tenantid;
    @JoinColumn(name = "propertyid", referencedColumnName = "property_id")
    @ManyToOne
    private Property propertyid;

    public Lease() {
    }

    public Lease(Integer leaseid) {
        this.leaseid = leaseid;
    }

    public Integer getLeaseid() {
        return leaseid;
    }

    public void setLeaseid(Integer leaseid) {
        this.leaseid = leaseid;
    }

    public Date getStartdate() {
        return startdate;
    }

    public void setStartdate(Date startdate) {
        this.startdate = startdate;
    }

    public Date getEnddate() {
        return enddate;
    }

    public void setEnddate(Date enddate) {
        this.enddate = enddate;
    }

    public Double getMonthlypayment() {
        return monthlypayment;
    }

    public void setMonthlypayment(Double monthlypayment) {
        this.monthlypayment = monthlypayment;
    }

    public Double getDeposit() {
        return deposit;
    }

    public void setDeposit(Double deposit) {
        this.deposit = deposit;
    }

    @XmlTransient
    public Collection<Payment> getPaymentCollection() {
        return paymentCollection;
    }

    public void setPaymentCollection(Collection<Payment> paymentCollection) {
        this.paymentCollection = paymentCollection;
    }

    public Tenant getTenantid() {
        return tenantid;
    }

    public void setTenantid(Tenant tenantid) {
        this.tenantid = tenantid;
    }

    public Property getPropertyid() {
        return propertyid;
    }

    public void setPropertyid(Property propertyid) {
        this.propertyid = propertyid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (leaseid != null ? leaseid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lease)) {
            return false;
        }
        Lease other = (Lease) object;
        if ((this.leaseid == null && other.leaseid != null) || (this.leaseid != null && !this.leaseid.equals(other.leaseid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rentaldb.Lease[ leaseid=" + leaseid + " ]";
    }
    
}
